package com.vgemv.jsutilitysdk.activity.jsaboutactivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.vgemv.jsutilitysdk.Application.JsBaseApplication;
import com.vgemv.jsutilitysdk.R;
import com.vgemv.jsutilitysdk.activity.BaseActivity.JsBaseActivity;
import com.vgemv.jsutilitysdk.activity.jsloglistactivity.JsLogListActivity;
import com.vgemv.jsutilitysdk.geometry.JsGeometryManager;
import com.vgemv.jsutilitysdk.JsView.JsLogoView.JsLogoView;

public class JsAboutActivity extends AppCompatActivity {

    RelativeLayout mRl_root = null;


    public static final String ImageResouceKey = "ImageResouceKey";
    public static final String TitleKey = "TitleKey";
    public static final String DetailKey = "DetailKey";

    private JsLogoView mLogoView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mRl_root = new RelativeLayout(this);
        setContentView(mRl_root);

        mLogoView = new JsLogoView(this);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        lp.setMargins(JsGeometryManager.pixelFromDp(20),JsGeometryManager.pixelFromDp(20),JsGeometryManager.pixelFromDp(20),0);
        mRl_root.addView(mLogoView,lp);

        Intent intent = getIntent();
        int resId = intent.getIntExtra(ImageResouceKey,0);
        //设置默认图片.
        if(resId == 0) {
            resId = R.mipmap.vgemv;
        }
        String title = intent.getStringExtra(TitleKey);
        if(title == null) {
            title = "广州骏视信息科技有限公司";
        }
        String detail = intent.getStringExtra(DetailKey);
        if(detail == null) {
            detail = String.format("%s(%s)_%s", JsBaseApplication.sharedInstance().getAppName(),JsBaseApplication.sharedInstance().getAppVersion(),JsBaseApplication.sharedInstance().getBuildType());
        }

        mLogoView.setImageResource(resId);
        mLogoView.setTitle(title);
        mLogoView.setDetail(detail);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        {
            MenuItem menuItem = menu.add("日志");
//            menuItem.setIcon(R.drawable.)
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(@NonNull MenuItem menuItem) {
                    Intent intent = new Intent(JsAboutActivity.this, JsLogListActivity.class);
                    startActivity(intent);
                    return false;
                }
            });
        }
        return super.onCreateOptionsMenu(menu);
    }



}
